using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using Terra.Core.Common.Models.Pagination;
using Terra.Core.Common.Models.Common;
using Terra.Core.Common.Models.Shared;
using Terra.Data.Entities.Identity;

namespace Terra.Data.Models.Identity
{
    /// <summary>
    /// 部门基础DTO
    /// </summary>
    public class DeptBaseDto
    {
        /// <summary>
        /// 部门ID
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 部门名称
        /// </summary>
        [Required(ErrorMessage = "部门名称不能为空")]
        [StringLength(50, ErrorMessage = "部门名称长度不能超过50个字符")]
        public string Name { get; set; }

        /// <summary>
        /// 部门编码
        /// </summary>
        [StringLength(50, ErrorMessage = "部门编码长度不能超过50个字符")]
        public string Code { get; set; }

        /// <summary>
        /// 部门全称
        /// </summary>
        [StringLength(100, ErrorMessage = "部门全称长度不能超过100个字符")]
        public string FullName { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [StringLength(500, ErrorMessage = "备注长度不能超过500个字符")]
        public string Remark { get; set; }

        /// <summary>
        /// 父部门ID
        /// </summary>
        public Guid? ParentId { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        public int Sort { get; set; } = 100;

        /// <summary>
        /// 部门状态：1-启用，0-禁用
        /// </summary>
        public int Status { get; set; } = 1;

        /// <summary>
        /// 部门负责人ID
        /// </summary>
        public Guid? LeaderId { get; set; }

        /// <summary>
        /// 部门层级路径
        /// </summary>
        public string Path { get; set; }

        /// <summary>
        /// 部门层级
        /// </summary>
        public int Level { get; set; } = 1;
    }

    /// <summary>
    /// 部门基本信息DTO
    /// </summary>
    public class DeptDto : DeptBaseDto
    {
        // 简化版，可以为空
    }

    /// <summary>
    /// 部门创建DTO
    /// </summary>
    public class DeptCreateDto : DeptBaseDto
    {

    }

    /// <summary>
    /// 部门更新DTO
    /// </summary>
    public class DeptUpdateDto : DeptCreateDto
    {
        /// <summary>
        /// 部门ID
        /// </summary>
        [Required(ErrorMessage = "部门ID不能为空")]
        public new Guid Id { get; set; }
    }

    /// <summary>
    /// 部门查询DTO
    /// </summary>
    public class DeptQueryDto : PagedRequest
    {
        /// <summary>
        /// 部门名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 部门编码
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 部门状态
        /// </summary>
        public int? Status { get; set; }

        /// <summary>
        /// 父部门ID
        /// </summary>
        public Guid? ParentId { get; set; }

        /// <summary>
        /// 查询所有层级
        /// </summary>
        public bool? IncludeAllLevels { get; set; }
    }

    /// <summary>
    /// 部门详情DTO
    /// </summary>
    public class DeptDetailDto : DeptBaseDto
    {
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public Guid? CreatedBy { get; set; }

        /// <summary>
        /// 创建人名称
        /// </summary>
        public string CreatedByName { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? LastModifiedTime { get; set; }

        /// <summary>
        /// 最后修改人
        /// </summary>
        public Guid? LastModifiedBy { get; set; }

        /// <summary>
        /// 最后修改人名称
        /// </summary>
        public string LastModifiedByName { get; set; }

        /// <summary>
        /// 父部门名称
        /// </summary>
        public string ParentName { get; set; }

        /// <summary>
        /// 部门负责人名称
        /// </summary>
        public string LeaderName { get; set; }

        /// <summary>
        /// 状态显示文本
        /// </summary>
        public string StatusText => Status == 1 ? "启用" : "禁用";
    }

    /// <summary>
    /// 部门列表项DTO
    /// </summary>
    public class DeptItemDto : DeptBaseDto
    {
        /// <summary>
        /// 父部门名称
        /// </summary>
        public string ParentName { get; set; }

        /// <summary>
        /// 部门负责人名称
        /// </summary>
        public string LeaderName { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// 状态显示文本
        /// </summary>
        public string StatusText => Status == 1 ? "启用" : "禁用";
    }

    /// <summary>
    /// 部门树节点DTO
    /// </summary>
    public class DeptTreeDto : DeptBaseDto
    {

        /// <summary>
        /// 父部门ID
        /// </summary>
        public new Guid? ParentId { get; set; }

        /// <summary>
        /// 是否为叶子节点
        /// </summary>
        public bool IsLeaf { get; set; }

        /// <summary>
        /// 子节点列表
        /// </summary>
        public List<DeptTreeDto> Children { get; set; } = new List<DeptTreeDto>();

        /// <summary>
        /// 附加数据
        /// </summary>
        public object Data { get; set; }
    }

    /// <summary>
    /// 部门选择项DTO
    /// </summary>
    public class DeptSelectDto : Terra.Core.Common.Models.Shared.SelectOption
    {
        /// <summary>
        /// 父部门ID
        /// </summary>
        public Guid? ParentId { get; set; }

        /// <summary>
        /// 部门编码
        /// </summary>
        public string Code { get; set; }
    }
}
